<template>
  <div class="container contract-review mb70">
    <p class="bread">
      <a :href="href" class="font-s-18">{{orderName}}</a> >
      <a href="javascript:void(0);" class="font-s-16">详情</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">交易监控订单详情</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="content bg-c-fff">
      <h3 class="tc">交易监控流程图</h3>
      <div class="progress-box rel">
        <company-name-container :companyNames="companyNames"></company-name-container>
        <div class="line" :class="{center: companyNames.length===2}" :style="{height: (events.length+0.5)*90+60+'px'}" v-show="events.length">
          <div class="arrow"></div>
        </div>
        <event-item v-for="(item,index) in events" :key="index" :state="item.state" :totalSides="companyNames.length" :side="item.side" :content="item.content" :files="item.files" :isCheck="true"></event-item>
      </div>
      <p :class="{tc: companyNames.length===2}" v-show="events.length">交易监控结束</p>
    </div>
  </div>
</template>
<script type="text/javascript">
import Step from '../components/Step'
import CompanyNameContainer from '../components/CompanyNameContainer'
import EventItem from '../components/EventItem'
export default {
  components: {
    Step,
    CompanyNameContainer,
    EventItem
  },
  data() {
    return {
      stepNum: 3,
      stepData: [{
        name: '查看资质审查报告'
      }, {
        name: '查看审查合同'
      }, {
        name: '监控师绘制流程图'
      }, {
        name: '监控员交易监控'
      }],
      companyNames: [],
      events: [],
      orderName: '',
      href: '',
      id: ''
    }
  },
  mounted() {
    this.id = this.$route.query.id
    if (this.$route.query.type === 'business') {
      this.orderName = '业务管理部-交易监控订单管理'
      this.href = '#/index/transaction-order-manage'
    } else if (this.$route.query.type === 'chief') {
      this.orderName = '首席监控师-交易监控订单管理'
      this.href = '#/index/cm-transaction-list'
    } else if (this.$route.query.type === 'businessNotice') {
      this.orderName = '业务管理部-交易监控通知'
      this.href = '#/index/transaction-notice'
    }
    this.getData()
  },
  methods: {
    getData() {
      this.$http.post('/transactionMonitorSer/sys/read/detail', {
        id: this.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.remark = data.data.data.remark
          this.status = data.data.data.status
          data.data.data.eventList.forEach(item => {
            let event = {}
            event.content = item.content
            event.side = item.memberOrder
            event.state = item.status
            event.files = item.fileList || []
            event.index = item.order
            event.id = item.id
            this.events.push(event)
          })
          data.data.data.memberList.forEach(member => {
            this.companyNames.push({
              name: member.memberName,
              id: member.id
            })
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    stepRouter(i, name) {
      if (i === 0 && this.status >= 2) {
        this.$router.push('/cm-transaction-aptitude?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
      }
      if (i === 1 && this.status >= 3) {
        this.$router.push('/cm-transaction-contract?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
      }
      if (i === 2 && this.status >= 4) {
        this.$router.push('/cm-transaction-drawing?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
      }
      if (i === 3 && this.status >= 5) {
        this.$router.push('/cm-transaction-flow?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.content {
  padding-bottom: 30px;
  margin-top: 20px;
}

.content h3 {
  line-height: 40px;
  border-bottom: 1px solid #ddd;
}

.line {
  position: absolute;
  width: 2px;
  top: 0;
  left: 65px;
  margin-top: 10px;
  background-color: #cfcfcf;
}

.line.center {
  left: 50%;
}

.line .arrow {
  position: absolute;
  bottom: -10px;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid #cfcfcf;
}

.content p {
  margin-top: 50px;
}

.progress-box {
  position: relative;
  width: 100%;
  background-color: #fff;
  overflow-x: auto;
  padding-bottom: 50px;
}

</style>
